<?php
namespace app\admin\controller;
use app\admin\model\Liuyan as LiuyanModel;

//商品管理类
class Liuyan extends Base
{
    /**
     * 留言列表
     */
    public function getLst()
    {
        $list = LiuyanModel::order('ly_create_time DESC')->paginate(10);

        $data = displayJson($list);

        $arr  = json_decode($data,true);

        $goodsIds  = array();
        $userIds   = array();

        $newArr   = $arr['data'];
        foreach ($newArr as $val) {
            $goodsIds[] = $val['ly_gid'];
            $userIds[]  = $val['ly_uid'];
        }

        $goods_list  = $this->getGoodsByIds($goodsIds);
        $user_list   = $this->getUserEmailByIds($userIds);

        foreach ($newArr as $key => $val) {
            $newArr[$key]['ly_uid'] = $user_list[$val['ly_uid']]['us_email'];
            $newArr[$key]['ly_gid'] = $goods_list[$val['ly_gid']];

            unset($newArr[$key]['ly_uname']);
            unset($newArr[$key]['ly_uimage']);
        }

        $arr['data']  = $newArr;

        $info['code'] = '200';
        $info['data'] = $arr;

        echo displayJson($info);die;
    }

    /**
     * 删除留言
     */
    public function delLiuyan()
    {
        $id = input('ly_id');

        if (empty($id)) {
            $info['code']    = '401';
            $info['message'] = '重要参数缺失，系统自动退出';
            echo displayJson($info);die;
        }

        $set['ly_status'] = 2;

        $res = db('liuyan',[],false)->where('ly_id',$id)->update($set);

        if ($res) {
            $info['code']    = '200';
            $info['message'] = '删除成功';
            echo displayJson($info);die;
        } else {
            $info['code']    = '400';
            $info['message'] = '删除失败';
            echo displayJson($info);die;
        }
    }



}
